package com.example.module.flipper;


import android.util.Log;
import android.view.View;
import android.view.animation.DecelerateInterpolator;

public final class SwapViews implements Runnable {
	private boolean mIsFirstView;
	private View prevView;
	private View nextView;

	public SwapViews(boolean isFirstView, View prevView, View nextView) {
		mIsFirstView = isFirstView;
		this.prevView = prevView;
		this.nextView = nextView;
	}

	public void run() {
		final float centerX = prevView.getWidth() / 2.0f;
		final float centerY = prevView.getHeight() / 2.0f;
		FlipAnimation rotation;

		Log.e("SwapViews", "mIsFirstView=" + mIsFirstView);
		
		if (mIsFirstView)
			rotation = new FlipAnimation(-90, 0, centerX, centerY, FlipSwicher.DEPTH, mIsFirstView);
		else
			rotation = new FlipAnimation(90, 0, centerX, centerY, FlipSwicher.DEPTH, mIsFirstView);
		
		prevView.setVisibility(View.GONE);
		nextView.setVisibility(View.VISIBLE);
		nextView.requestFocus();

		Log.e("SwapViews", "prevView=" + prevView.getVisibility() + " nextView=" + nextView.getVisibility());
		
		rotation.setDuration(FlipSwicher.DURATION);
		rotation.setFillAfter(true);
		rotation.setInterpolator(new DecelerateInterpolator());

		nextView.startAnimation(rotation);
	}
}
